home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / pcxbgi2.exe / lha / TPDEMO1.PAS < prev    next >
Pascal/Delphi Source File  |  1991-03-03  |  4KB  |  98 lines

  1.  
  2. {****************************************************************************
  3. *  Program: TPDemo1.pas                                                     *
  4. *   Author: Marty Balash                                                    *
  5. *     Date: 03/02/91                                                        *
  6. *  Remarks: How to display an .MJB image using Turbo Pascal                 *
  7. *                                                                           *
  8. *  NOTE:  o - Create (partial screen) image using PCX2BGI.EXE               *
  9. *             (DEMO.PCX was used to create the images for this program)     *
  10. *         o - Run TPCONV.EXE using .MJB file from PCX2BGI.EXE to create     *
  11. *              .HDR and .DAT files for input to your Turbo Pascal program   *
  12. *               and to get the size of the array to hold the image          *
  13. *         o - Display the image as demonstrated in this code                *
  14. *         o - Send $15.00 to:                                               *
  15. *                                                                           *
  16. *                Marty Balash                                               *
  17. *                2 Pinecrest Dr.                                            *
  18. *                Prospect CT 06712                                          *
  19. ****************************************************************************}
  20.  
  21. program tpdemo;
  22. uses crt,graph;
  23.  
  24. {
  25.   *** NOTE: Following two constants will be needed for each image loaded ***
  26. }
  27. const basefn = 'BGI1'; { Filename without HDR/DAT ext }
  28. const imsize = 7702;   { 7702 = Size of image reported by TPCONV.EXE }
  29.  
  30. type imagehdr = record            { imagehdr - Describes header info }
  31.   id      : array [1..8] of char; { id       - This should be 'PCX2BGI' }
  32.   size    : word;                 { size     - For TC programs (not needed) }
  33.   palette : palettetype;          { palette  - Use SetAllPalette to set }
  34. end;
  35.  
  36. type imagedata =                  { A type (of the correct size) is needed }
  37.   array[1..imsize] of byte;       { for each different image loaded        }
  38.  
  39. var
  40.   hdr:imagehdr;                   { hdr - Verify fmt & get palette to use }
  41.   dat:imagedata;                  { dat - Display this buffer with PutImage }
  42.  
  43. procedure openegascreen;          { Open 640x350 16-color EGA screen }
  44. var
  45.   driver,mode,result:integer;
  46. begin
  47.   driver := ega;
  48.   mode := egahi;
  49.   initgraph(driver,mode,'');
  50.   result := graphresult;
  51.   if result <> grok then
  52.     begin
  53.       write('ERROR: ',grapherrormsg(result));
  54.       exit;
  55.     end;
  56. end;
  57.  
  58. procedure readimage;
  59. var
  60.   hdrhandle:file of imagehdr;  { Header will be retrieved in one read }
  61.   dathandle:file of imagedata; { Data will be retrieved in one read }
  62.   hdrname:string[7];           { For testing file format }
  63.   hdrfn:string[12];
  64.   datfn:string[12];
  65. begin
  66.   hdrfn:=basefn+'.HDR';        { Create filenames }
  67.   datfn:=basefn+'.DAT';
  68.   assign(hdrhandle,hdrfn);     { Open the header file ... }
  69.   {$I-}
  70.   reset(hdrhandle);
  71.   {$I+}
  72.   if ioresult <> 0 then
  73.     exit;
  74.   read(hdrhandle,hdr);         { Read header }
  75.   close(hdrhandle);            { Close header file }
  76.   hdrname:=hdr.id[1]+hdr.id[2]+hdr.id[3]+hdr.id[4]+hdr.id[5]+hdr.id[6]+hdr.id[7];
  77.   if hdrname <> 'PCX2BGI' then { Verify file format }
  78.     exit;
  79.   setallpalette(hdr.palette);  { Set palette to image palette }
  80.   assign(dathandle,datfn);     { Open the data file ... }
  81.   {$I-}
  82.   reset(dathandle);
  83.   {$I+}
  84.   if ioresult <> 0 then
  85.     exit;
  86.   read(dathandle,dat);         { Read data }
  87.   close(dathandle);            { Close data file }
  88. end;
  89.  
  90. begin                          { MAIN PROGRAM }
  91.   openegascreen;               { Open EGA hi-res screen }
  92.   readimage;                   { Read image from disk }
  93.   putimage(0,0,dat,NormalPut); { Put the image on the screen }
  94.   repeat until keypressed;     { Wait until keypress }
  95.   closegraph;                  { Done }
  96.   writeln('Created with LBM2BGI.EXE by Marty Balash');
  97. end.
  98.